//index.js
//获取应用实例
const app = getApp()
const api = require('../../utils/api.js');
const util = require('../../utils/util.js');
Page({
	data: {
		courseTime:util.formatTime(new Date(),0),
		pageNum:1,
		total:0,
		businessId:"",
		kcList:"",
	},
	//事件处理函数
	loadMore: function() {
		let _this = this;
		if(this.data.total > this.data.pageNum * 20){
			setTimeout(function(){
				_this.setData({
					pageNum: _this.data.pageNum + 1
				});
				_this.searchList();
			},500);
		}else{
			console.log(this.data.pageNum)
		}
	},
	searchList:function(){
		let _this = this;
		api.getCourseWXList({
			data: {
				pageNum: this.data.pageNum,
				pageSize: 20,
				courseOwner: this.data.businessId,
				courseTime:this.data.courseTime
			},
			success: function(res) {
				if(res.data.code == 0) {
					res.data.list.rows.forEach(function(item){
						item.strDate = util.formatEndTime(item.subTime,0)+ " ~ " +
						util.formatEndTime(item.subTime,item.subCourseDuration);
					});
					
					_this.setData({
						kcList: res.data.list.rows,
						total:res.data.list.total
					});
				}
			},
		});
	},
	bindDateChange: function(e) {
		this.setData({
			courseTime: util.formatTime(new Date(e.detail.value),0)
		});
		this.searchList();
	},
	onLoad: function() {
		let _this = this;
		wx.getStorage({
		 	key: 'customerId',
		  	success: function(res) {
		  		_this.setData({
					businessId: res.data
				});
		      	_this.searchList();
		  	} 
		})
	}

})